package cn.ztr.ymcc.mq;

import cn.ztr.ymcc.constans.Mqcons;
import cn.ztr.ymcc.domain.MediaFile;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.client.producer.SendStatus;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class MediaProducer {
    @Autowired
    private RocketMQTemplate rocketMQTemplate;
     public boolean sysSend(MediaFile mediaFile){
         String s = JSON.toJSONString(mediaFile);
         SendResult sendResult = rocketMQTemplate.syncSend(Mqcons.TOPIC_COURSE_VIDEO, MessageBuilder.withPayload(s).build());
         return sendResult.getSendStatus()== SendStatus.SEND_OK;
     }

}
